package com.jcl.recruit.depart.logic;

import com.jcl.core.constants.Constant;
import com.jcl.recruit.core.constants.Constants;
import com.jcl.recruit.depart.dao.DepartmentDao;
import com.jcl.recruit.org.model.Department;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @ClassName DepartmentLogic

 * @Author yyliu
 * @Date 2018/9/12 18:49
 * @Version 1.0
 **/
@Component
public class DepartmentLogic {

    @Autowired
    private DepartmentDao departmentDao;

    public Department addRoot(String fullName, Integer companyId, String corpCode) {
        Department department = new Department();
        department.setFullname(fullName);
        department.setShortname(fullName);
        department.setSubcompanyId(companyId);
        department.setCorpCode(corpCode);
        department.setSuperId(Constants.DepartmentInfo.ROOT_SUPER_ID);
        department.setCode(Constant.NUMBER_0 + "");
        department.setShoworder(Constant.NUMBER_1);
        departmentDao.add(department);
        return department;
    }

    public List<Department> selectDepartmentListsBySupperIdAndCompanyIdAndKeyword(Integer superId,
                                                                                  Integer subcompanyId,
                                                                                  String keyword) {
        return departmentDao.selectDepartmentListsBySupperIdAndCompanyIdAndKeyword(superId, subcompanyId, keyword);
    }

    public Department findRootByCorpCode(String corpCode,
                                         Integer superId) {
        return departmentDao.findRootByCorpCode(corpCode, superId);
    }

    public Department selectPrimarykeyById(Integer id) {
        return departmentDao.selectPrimarykeyById(id);
    }

    public List<Department> selectAllDepartmentsBySubaccountId(Integer superId,
                                                               Integer subcompanyId) {
        return departmentDao.selectAllDepartmentsBySubaccountId(superId, subcompanyId);
    }

    public int add(Department department) {
        return departmentDao.add(department);
    }
}
